// pages/home/home.js
Page({
    data: {
        currentCity:""
    },
    onLoad(){
        wx.getLocation({
          altitude: '(false)',
          type:"wgs84",
          success:(res)=>{
              var {latitude,longitude}=res;
              console.log(res);
              /* 根据经纬度获取当前位置 */
              key="YGQBZ-POB3P-5JODH-VCNLQ-HDVNJ-FKBZF";
              var url=`https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77&get_poi=1`
              wx.request({
                  url,
                  header:{'content-type':'application/json'},
                  method:'GET',
                  dataType:'json',
                  responseType:'text',
                  success:(res)=>{
                      var city=res.data.result.address_component.city;
                      var storageCity=wx.getStorageSync("city")
                      if(currentCity!=storageCity){
                          wx.showModal({
                            cancelColor: 'cancelColor',
                          })
                      }
                      this.setData({
                          currentCity:city
                      })
                  }
              })
            }
        })
    },
    handleClick(){
        wx.navigateTo({
            url: '/pages/city/city',
        })
    },

    
    onShow: function () {
        var city=wx.getStorageSync('city')
        this.setData({
            currentCity:city
        })
    }
})